import operator

films = [('姜子牙', 60, 8.3), ('夺冠', 65, 9.1), ('金刚川', 50, 9.4),
         ('汪汪队立大功之超能救援', 70, 8.2), ('我和我的家乡', 80, 9.2),
         ('星际穿越', 85, 9.3)]


def print_films(films):
    for i, j in enumerate(films, 1):
        print(f'{i} -- Movie: {j[0]} -- Price: {j[1]} -- Score: {j[2]}')


# print('1', '-' * 32)  # sort by nature
# films.sort()
# print_films(films)
# print('2', '-' * 32)  # sort by key 1
# films.sort(key=operator.itemgetter(1), reverse=True)
# print_films(films)
# print('3', '-' * 32)  # sort by key 2
# films.sort(key=operator.itemgetter(2), reverse=True)
# print_films(films)
# print('4', '-' * 32)  # sort by lambda
films.sort(key=lambda x: x[1], reverse=True)
# print_films(films)

# movie booking office system
menu = ('查看热映', '订票', '退票', '结账', '影评')
selected = []
words = []
while True:
    print('-' * 32)
    print('Welcome!')
    for i, j in enumerate(menu, start=1):
        print(i, j)
    print('-' * 32)

    ch = int(input('Plz enter your service option:'))
    if ch == 1:
        print_films(films)
    elif ch == 2:
        while True:
            print('Selected: ')
            # for name, price, score in selected:
            #     print(f'{name}, {price}, {score}')
            for el in selected:
                print(el[0], el[1], el[2])
            n = int(input('Plz choose movie: (0 for quit)'))
            if n == 0:
                break
            selected.append(films[n - 1])
    elif ch == 3:
        while True:
            print('Your have selected below movies:')
            for i, j in enumerate(selected):
                print(f'{i+1} - {j[0]}')
            m = int(input('Plz input the number of the movie you want to refund. (0 for quit)'))
            if m == 0:
                break
            else:
                selected.pop(m - 1)
    elif ch == 4:
        money = 0
        for i in selected:
            print(f'{i[0]}, {i[1]}')
            money += i[1]
        print(f'You should pay {money}')
        payed = float(input('Plz pay for them:'))
        if payed < money:
            print('Not adequate.')
        else:
            change = payed - money
            print(f'Change: {change}')
    elif ch == 5:
        while True:
            print('Comments:')
            for comment in words:
                print('\t>{}'.format(comment))
            ch = input('Plz write down your comment: (empty for quit)').strip()
            if '' == ch:
                break
            else:
                words.append(ch)
    else:
        break

